#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--) 
	{
        int n;
        cin >> n;
        vector<pair<int, int> > ans;
        multiset<pair<int, int> > s;
        for (int i = 1; i <= n; i++) 
		{
            int x;
            cin >> x;
            s.insert(make_pair(x, i));
        }
        int idx = 0;
        while (!s.empty()) 
		{
            while (s.begin()->first != 0) 
			{
                auto it = s.end();
                it--;
                ans.push_back(make_pair(s.begin()->second, it->second));
                pair<int, int> temp2 = *it;
                pair<int, int> temp = *s.begin();
                temp2.first--;
                temp.first--;
                s.erase(s.begin());
                s.erase(s.find(*it));
                s.insert(temp2);
                s.insert(temp);
            }
            s.erase(s.begin());
            if (s.size() == 1) break;
        }
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) 
		{
            int x = ans[i].first, y = ans[i].second;
            if (x > y) swap(x, y);
            cout << x << " " << y << endl;
        }
    }
    return 0;
}
